<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="Content-type" content="text/html; charset=utf-8"/>
	<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,minimum-scale=1,user-scalable=no"/>
	<meta name="apple-mobile-web-app-capable" content="yes"/>
	<title>EdgeToEdgeDataList - Load More</title>

	<script type="text/javascript" src="../deviceTheme.js" data-dojo-config="mblThemeFiles: ['base']"></script>
	<script type="text/javascript" src="../../../dojo/dojo.js" data-dojo-config="async: true, parseOnLoad: true"></script>

	<script type="text/javascript">
		require([
			"dojo/_base/Deferred",
			"dojox/data/QueryReadStore",
			"dojo/ready",
			"dijit/registry",
			"dojox/mobile/ListItem",
			"dojox/mobile/parser",
			"dojox/mobile",
			"dojox/mobile/compat",
			"dojox/mobile/ScrollableView",
			"dojox/mobile/EdgeToEdgeDataList"
		], function(Deferred, QueryReadStore, ready, registry, ListItem){
			//var url = "data/fruits.json";
			var url = "data/fake_service.php";
			store = new QueryReadStore({url: url});

			var start = 1,
				count = 5,
				loadMoreItem = null,
				list = null;
			function loadMore(){
				loadMoreItem.set({
					busy: true,
					label: "Loading More Items..."
				});
				setTimeout(function(){ // to simulate network latency
					Deferred.when(list.setQuery({start:start, count:count}), function(){
						loadMoreItem.set({
							busy: false,
							label: "Load More Items..."
						});
						list.removeChild(loadMoreItem);
						list.addChild(loadMoreItem);
					});
					start += count;
					return false;
				}, 3000);
			};
			function addLoadMoreItem(){
				if(!loadMoreItem){
					loadMoreItem = new ListItem({
						label: "Load More Items...",
						onClick: loadMore,
						moveTo: "#",
						noArrow: true
					});
				}
				list.addChild(loadMoreItem);
			}

			ready(function(){
				list = registry.byId("list");
				Deferred.when(list.setStore(store, {start:start, count:count}), addLoadMoreItem);
				start += count;
			});
		});
	</script>
</head>
<body style="visibility:hidden;">
	<div data-dojo-type="dojox.mobile.ScrollableView">
		<h1 data-dojo-type="dojox.mobile.Heading" data-dojo-props='fixed:"top"'>EdgeToEdgeDataList</h1>
		<ul data-dojo-type="dojox.mobile.EdgeToEdgeDataList" id="list" data-dojo-props='append:true'></ul>
	</div>
</body>
</html>
